
//jqueryAjax
var QueueFactory = new QueuedHandler();


/**
 * 商品竞拍
 */
$(document).ready(function() {
	showProductImage();   //显示商品竞拍图片
   
    window.price = new Array();   //商品竞拍金额数组
});






/**
 * 竞拍商品图片显示控制
 */
function showProductImage() {
    $("#proImage img").not(":first").hide();
    $("#proThumbnail a").click(function() {
        if ($("#" + this.rel).is(":hidden")) {
            $("#proImage img").slideUp();
            $("#" + this.rel).slideDown()
        }
    }).focus(function() {
        $(this).blur()
    })
}



/**
 * 商品竞拍属性
function showAuctionAttributeTag() {
    $(".countdownCap, .newGuy, .returnPoint, .morning, .evening, .bidMirror, .limitBid, .bidDegree, .bidReturnCap, .bidReturnAll, .freeBid, .combinationBid,.countdownRandom").mouseover(function() {
        $(this).attr("id", "currentTag");
        var self = $(this).attr("id");
        jt(self);
        var tagContent = $("#currentTag").attr("jtContent");
        $("#jtContent").html(tagContent)
    }).mouseout(function() {
        $("#jt").remove();
        $(this).attr("id", " ")
    })
};
*/




/**
 * html.html
 * 初始化首页正在竞拍商品
 * @param v  所有正在竞拍中的商品
 * @returns {Boolean}
 */
function inibid(v) {
    if (v != '') {
        window._Fbid = 0;
        window._Alive = 0;
        window._R = 0;
        window._T = new Array();
        window._V = '0';
        window._C = 0;
        
        window._BID = new Array();
        window.BidTimer = null;
        window.ShowTimer = null;
        
        getVal();
        
        
        //初始化按钮
        //竞拍按钮
        $(".bidbutton").mouseover(function() {
            var islogin = getCookie('islogin');
            var isfinish = $(this).hasClass("bidImgButton_ended");
            if (!islogin && !isfinish) {  //未登录并且未结束
                $(this).attr("class", "bidbutton bidImgButton bidImgButton_login")
            }
        });
        
        $(".bidbutton").mouseout(function() {
            var islogin = getCookie('islogin');
            var isfinish = $(this).hasClass("bidImgButton_ended");
            if (!islogin && !isfinish) {
                $(this).attr("class", "bidbutton bidImgButton bidImgButton_live")
            }
        });
        
        $(".bidbutton").click(function() {
            var bd = $(this).attr("id");
            var d = $(this).attr("name");
            var t = $(this).attr("title");
            
            var islogin = getCookie('islogin');
            var isfinish = $(this).hasClass("bidImgButton_ended");
            if (!isfinish) {
                if (!islogin) {   //未登录
                    loadloginbox()  //弹出登录窗口
                } else { //已登录商品未竞拍结束
                    if (bid(bd, d, t)) {    //执行竞拍
                        $(this).attr("class", "bidbutton bidImgButton bidImgButton_live")
                    }
                }
            }
        });
        
        
        
        
        //保价购买
        $(".buynow").mouseover(function() {
            var islogin = getCookie('islogin');
            if (!islogin) {
                $(this).text('请先登录')
            }
        });
        $(".buynow").mouseout(function() {
            var islogin = getCookie('islogin');
            if (!islogin) {
                $(this).text('保价购买')
            }
        });
        $(".buynow").click(function() {
            var islogin = getCookie('islogin');
            var d = $(this).attr("name");
            if (!islogin) {  //未登录，弹出登录窗口
                loadloginbox() 
            } else {
                if (buynow(d)) {
                    $(this).text('保价购买')
                }
            }
        });
        
        
        return true
    }
}



function getVal() {
    countRef();
}
function countRef() {
    window._C = window._C + 1;
    if (window._C >= 8) {
        window._R = 1;
        window._C = 0
    }
}



/**
 * 消息Tip提示
 * @param id
 * @param text
 */
function showBidTip(id, text) {
    jt($("#" + id).parent().parent().attr("id"));
    $("#jtContent").html(text);
    function showJT() {
        $("#jt").fadeOut("fast", 
        function() {
            $(this).remove()
        })
    }
    var tt = window.setTimeout(showJT, 1500);
    $("#jt").hover(function() {
        window.clearTimeout(tt)
    },
    function() {
        tt = window.setTimeout(showJT, 1000)
    });
    $("#jt").blur(function() {
        showJT()
    })
}




/**
 * 点击竞拍
 * @param id  竞拍ID
 * @param key
 */
function bid(id, key) {
    $.ajax({
        type: "POST",
        //timeout: _ajaxtimeout,
        url: ROOT + "/bid.php",  //异步提交竞拍
        data: {
            "id": key
        },
        success: function(vv) {
            v = eval(vv);
            msg = v[0];
            ext = v[1];
            if (msg == 1) {
                showBidTip(id, '<span>出价成功，消耗<strong style="color:#ff0000">' + ext + '点</strong></span>');
                window._R = 1;
                window.setTimeout("up_self()", 500)
            } else if (msg == 0) {
				showBidTip(id, '此竞拍已结束')
			} else if (msg == 2) {
                showBidTip(id, '请先登录')
            } else if (msg == 3) {
                showBidTip(id, '您的余额不足，请充值!<a href="javascript:paycountnow();" title="充值，获取'+BEATNAME+'">【马上充值】</a>')
            } else if (msg == 4) {
                var msg = '<div class="tc"><span class="button"><span class="first-child"><button onclick="removeDialogbox(\'#userAway\');" type="button">您已出价，无需重复!</button></span></span></div>';
                addDialogbox("#userAway", WEBNAME + '提示', 10010, 300);
                $("#userAway .dialogboxContent").html(msg)
            } else if (msg == 5) {} else if (msg == 6) {
                showBidTip(id, '现已经到达封盘时段（00:00 - 09:00），请于开盘时再竞拍')
            } else if (msg == 7) {
                showBidTip(id, '此竞拍不存在')
            } else if (msg == 8) {
                showBidTip(id, '竞拍未开始');
            } else if (msg == 9) {
                showBidTip(id, '异常错误');
            } else if (msg == 10) {
                showBidTip(id, '您已获得过商品，此为新人竞拍商品')
            } else if (msg == 11) {
                showBidTip(id, '您出价太快，请放松')
            } else if (msg == 12) {
                showBidTip(id, '此为新人竞拍商品，请先进行账户安全认证')
            } else if (msg == 13) {
                showBidTip(id, '检测点击频率太快，暂停出价30秒')
            } else if (msg == 14) {
                showBidTip(id, '您已设置分身进行竞拍，请取消或者等待分身出价结束后再操作！')
            } else if (msg == 15) {
                showBidTip(id, '本期是"N次拍"游戏,您的出价已经达到"N次拍"玩法的次数的上限！')
            } else if (msg == 16) {
                showBidTip(id, '本次竞拍只限' + ext + '期出价的网友！')
            } else if (msg == 17) {
                showBidTip(id, '竞拍封顶规则限制，您不能参与此次竞拍！')
            } else if (msg == 18) {
                showBidTip(id, '您已获得过此商品，不能参与此次竞拍！')
            } else if (msg == 19) {
                showBidTip(id, '相同网络地址已有会员出价，您不能参与此次竞拍！')
            } else if (msg == 20) {
                showBidTip(id, '您的出价已经达到本期竞拍出价次数上限！')
            } else {}
        }
    })
}




/**
 * 保价购买
 * @param id
 */
function buynow(id) {
    var buyId = "buy_" + id;
    QueueFactory.request({
        type: "POST",
        url: APP + "/Auction/buynow/id/" + id,
        success: function(msg) {
            if (msg == 0) {
                showBidTip(buyId, '保价购买成功，本期竞拍结束后将生成保价订单。<br /><br />在这个过程中仍然可以参与竞拍，以争取获更低的价格。')
            } else if (msg == 1) {
                showBidTip(buyId, '保价失败，请重试')
            } else if (msg == 2) {
                showBidTip(buyId, '请先登录，后再进行保价购买')
            } else if (msg == 3) {
                showBidTip(buyId, '您已保价，本期竞拍结束后将生成保价订单。请不要重复点击！')
            }
        }
    })
}











/**
 * footer.html
 * 异步获取商品竞拍情况
 * @param v
 * @returns {Boolean}
 */
function ajaxGetVal(v) {
	if (window.inibidjs == '') {   //没有正在进行竞标的
		return false
	}
	
	var d = new Date();
	window.ajaxthead = $.ajax({
	   type: "POST",
	   timeout:5500,
	   url: THREAD,
	   data: "id=" + window.inibidjs + "&_t=" + d.getTime() + "&_v=" + v,
	   cache: false,
	   dataType:"json",
	   success: function(data){  //成功执行信息异步刷新继续调用
		  displayBid(data);
	   },
	   error: function(data){
		   window.ajaxthead.abort();
		   ajaxGetVal(0);  //失败继续调用
	   }
	});
	
}



/**
 * 异步获取商品竞拍情况信息处理
 * @param data
 */
function displayBid(data) {
	var v = data._v;
	var d = data._d;
	for(var i=0;i < d.length ;i++){
		var key = d[i]['id'];  //竞拍ID
		
		dotime(key, d[i]['end']);   //结束秒数
		
		dobider(key, d[i]['name'], d[i]['uid'], d[i]['head']);  //竞拍人姓名、ID、头像
		
		doprice(key, d[i]['price']);  //竞拍金额
		
		dostatus(key, d[i]['state']);  //商品竞标状态
		
		up_history();
	}
	
	window.ajaxthead.abort();
	
	ajaxGetVal(v);  //继续调用
}


/**
 * 商品竞拍时间处理
 * @param key
 * @param v
 */
function dotime(key, v) {
    var id = $('#time_'+key);
    id.countdown('destroy');
	id.countdown({
		until: v, 
		compact: true,
		format: 'HMS',
		expiryText:"即将成交",
		onTick:function(periods){
			timeslot(periods,key);
		}
	});
}


/**
 * 商品竞拍对于时间段颜色的操作
 * @param periods
 * @param key
 */
function timeslot(periods,key){
	var key = 'time_'+key;
	var id = $('#'+ key);
	var time = periods[4]*3600 + periods[5]*60 + periods[6];

		if(time < 30){
			if(time < 20){
				if(time < 10){
					if(window._T[key] != 'red'){
						id.css("color","red");
						window._T == 'red';
					}
				}else{
					if(window._T[key] != 'green'){
						id.css("color","green");
						window._T == 'green';
					}
				}
			}else{
				
				if(window._T[key] != 'yellow'){
					id.css("color","yellow");
					window._T[key] == 'yellow';
				}
			}
		}else{
			if(window._T[key] != 'black'){
				id.css("color","black");
				window._T[key] == 'black';
			}
		}
}



/**
 * 商品竞拍人处理
 * @param key
 * @param name
 * @param uid
 * @param head
 */
function dobider(key,name,uid,head) {
	var bidder_id = "#bidder_" + key;
    var bidder_icon = "#bidder_icon_" + key;
    if (name != '') {
        $(bidder_id).text(name);
        $(bidder_id).attr("href", APP + "/User/center/id/" + uid);   //查看竞标人信息
        $(bidder_id).attr("target", "_blank");
        $(bidder_id).attr("title", "去看看" + name);
        $(bidder_icon).html('<img src="'+ROOT+'/Public/images/head/s/' + head + '" />');   //竞标人头像
        $(bidder_icon).attr("href", APP + "/User/center/id/" + uid);
        $(bidder_icon).attr("target", "_blank");
        $(bidder_icon).attr("title", "去看看" + name);
    } else {
        $(bidder_id).text('----');
        $(bidder_id).attr("title", "暂无用户竞拍");
        $(bidder_icon).html('<img src="'+ROOT+'/Public/images/head/s/userDefaultIcon.gif" />');
    }
}


/**
 * 商品竞标竞标金额处理
 * @param key
 * @param v
 */
function doprice(key, v) {
	var id = "#price_" + key;
    v = Ftmath(v);
    $(id).text("¥" + v);
    if (window.price['price_'+key]!= v) {
        $(id).highlightFade({
            color: 'red',
            speed: 800
        })
    }
    price['price_'+key] = v;   //存入数组
}


/**
 * 商品竞标状态处理
 * @param id
 * @param v
 * 
 * 
 * 即将竞拍：（未开始） 历史竞拍：（竞拍结束和生成订单）
 * 未开始0  进行中1 已结束2 已产生订单3
 * 
 */
function dostatus(id, v) {
    var bidNo = window.inibidjs;  //正在进行竞拍商品
    var ids = bidNo.split(",");
    if (v == '0') {    //
        doTips(id);
        dostopstyle(id);
        clearbid(id);
    }else if(v == 3){  
		clearbid(id);
		dostopstyle(id);
	}
}




/**
 * 竞标结束
 * 正在进行竞标中去掉这个竞拍
 * @param n
 */
function clearbid(n) {
	  var ids = window.inibidjs.split(",");  //正在进行竞拍商品
	  var tempvar = new Array();
	  var k = 0;
	  for (var i = 0; i < ids.length; i++) {
	      if (n != ids[i]) {
	          tempvar[k++] = ids[i]
	      }
	  }
	  window.inibidjs = tempvar.join(',')
}


/**
 * 竞标结束 信息都设置为空
 * @param id
 */
function dostopstyle(id) {
    $("#time_" + id).text('--:--:--').attr('style', 'color:#a6a6a6');
    $("#bid_btn_" + id).addClass('button-disabled');
    $("#" + id).attr("class", "bidbutton bidImgButton bidImgButton_ended");
}




/**
 * 商品竞拍信息提示
 * @param id
 */
function doTips(id) {
    $.ajax({
        type: "POST",
        timeout: _ajaxtimeout,
        url: APP + "/Auction/gamesTips",
        data: {
            "id": id
        },
        success: function(tips) {
            var v = eval(tips);
            var info = v[0];
            var ext = v[1];
            var t = v[2];
            var g = v[3];
            if (t == 0) {   //不提示
                $("#proTop").hide()
            } else {
                $("#proTop").show();
                
                window.setTimeout("HideTips()", 30000);   //关闭信息提示
                
                //   0自己获取结束提示       1提示保价     3提示正常结束             [ 2第2名         4返点        5恭喜他人   后台没有功能]
                
                if (g == 1) {
                	/*
                    var lastopplayer = info['lastopplayer'];
                    var lastopid = info['lastopid'];
                    var pname = info['productname'];
                    
                    var content = setFunGameTips(lastopplayer, lastopid, pname);
                    $("#alertOrderContent").html(content)
                    */
                    
                } else {
                    switch (ext) {
	                    case 0:
	                        var price = info['price'];
	                        var time = info['endtime'];
	                        var pname = info['productname'];
	                        var grid = info['weight'];
	                        var content = setGameTips0(price, pname, grid, time);
	                        $("#alertOrderContent").html(content);
	                        break;
	                    case 1:
	                        var lastopplayer = info['lastopplayer'];
	                        var pname = info['productname'];
	                        var price = info['price'];
	                        var saleprice = info['saleprice'];
	                        var time = info['endtime'];
	                        var grid = info['weight'];
	                        var content = setGameTips1(lastopplayer, price, pname, grid, saleprice, time);
	                        $("#alertOrderContent").html(content);
	                        break;
	                    case 2:
	                    	/*
	                        var lastopplayer = info['lastopplayer'];
	                        var backcounts = info['backcounts'];
	                        var acount = info['acount'];
	                        var bcount = info['bcount'];
	                        var price = info['price'];
	                        var saleprice = info['saleprice'];
	                        var time = info['endtime'];
	                        var pname = info['productname'];
	                        var grid = info['weight'];
	                        var content = setGameTips2(lastopplayer, price, saleprice, pname, grid, acount, bcount, backcounts, time);
	                        $("#alertOrderContent").html(content);
	                        */
	                        break;
	                    case 3:
	                        var lastopplayer = info['lastopplayer'];
	                        var price = info['price'];
	                        var pname = info['productname'];
	                        var content = setGameTips3(lastopplayer, price, pname);
	                        $("#alertOrderContent").html(content);
	                        break;
	                    case 4:
	                    	/*
	                        var lastopplayer = info['lastopplayer'];
	                        var price = info['price'];
	                        var pname = info['productname'];
	                        var acount = info['acount'];
	                        var bcount = info['bcount'];
	                        var backcounts = info['backcounts'];
	                        var content = setGameTips4(lastopplayer, pname, price, acount, bcount, backcounts);
	                        $("#alertOrderContent").html(content);
	                        */
	                        break;
	                    case 5:
	                    	/*
	                        var lastopplayer = info['lastopplayer'];
	                        var price = info['price'];
	                        var pname = info['productname'];
	                        var content = setGameTips5(lastopplayer, price, pname);
	                        $("#alertOrderContent").html(content);
	                        */
	                        break;
	                    default:
	                        break
	                    }
                }
            }
        }
    })
}



/*
function setFunGameTips(winner, winnerid, pname) {
    var content = '<h3 id="endedPrice">恭喜' + winner + '刚刚在趣味区' + '拍得[ ' + pname + ' ]' + '</h3>' + '<div id="orderExpiryDate">' + '<p class="notice">公平竞拍的环境需要您的支持，请勿触犯' + WEBNAME + '一人多号规则，再次提醒用户阅读' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《违规处理》</a>' + '、' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《使用条款》</a>' + '</p>' + '</div>' + '<div id="userButton" class="fr">' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
*/
function setGameTips0(price, pname, grid, time) {
    var content = '<h3 id="endedPrice">恭喜，您以' + '<span class="price">¥' + price + '</span>拍得[ ' + pname + ' ]！' + '</h3>' + '<div id="orderExpiryDate">' + '<p>订单有效期至<strong>' + time + '</strong>，请及时支付订单，逾期视为放弃购买。</p>' + '<p class="notice">您已拍得商品，切勿触犯' + WEBNAME + '一人多号规则，再次提醒用户阅读' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《违规处理》</a>' + '、' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《使用条款》</a>' + '</p>' + '</div>' + '<div id="userButton" class="fr">' + '<span class="button button-hilite">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="goToURL()">前往操作</button>' + '</span>' + '</span>' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
function setGameTips1(lastopplayer, price, pname, grid, dcount, time) {
    var content = '<h3 id="endedPrice">[ ' + pname + ' ]竞拍已结束！您可补差价' + '<span class="price">¥' + dcount + '</span>进行保价购买，不浪费一分钱' + '</h3>' + '<div id="orderExpiryDate">' + '<p>订单有效期至<strong>' + time + '</strong>，' + '请及时支付订单，逾期视为放弃购买。</p>' + '<p class="notice">您已拍得商品，再次提醒用户阅读' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《违规处理》</a>' + '、' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《使用条款》</a>' + '</p>' + '</div>' + '<div id="userButton" class="fr">' + '<span class="button button-hilite">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="goToURL()">前往操作</button>' + '</span>' + '</span>' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
/*
function setGameTips2(lastopplayer, price, saleprice, pname, grid, acount, bcount, backcounts, time) {
    var content = '<h3 id="endedPrice">[ ' + pname + ' ]竞拍已结束！' + '您获得第二名返点资格' + '</h3>' + '<div id="orderExpiryDate">' + '<p>订单有效期至<strong>' + time + '</strong>，' + '您可选择补差价<span class="price">¥' + saleprice + '</span>“保价购买”或选择返点<strong>' + backcounts + '</strong>'+POINTBNAME+'。' + '<p>竞拍已结束，请参与其他竞拍，切勿触犯' + WEBNAME + '一人多号规则，再次提醒用户阅读' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《违规处理》</a>' + '、' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《使用条款》</a>' + '</p>' + '</div>' + '<div id="userButton" class="fr">' + '<span class="button button-hilite">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="goToURL()">前往操作</button>' + '</span>' + '</span>' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
*/
function setGameTips3(lastopplayer, price, pname) {
    var content = '<h3 id="endedPrice">' + lastopplayer + '刚以' + '<span class="price">¥' + price + '</span>获得了商品[ ' + pname + ' ]' + '</h3>' + '<div id="orderExpiryDate">' + '<p>本次竞拍已结束，请参与其他竞拍!' + '</p>' + '<p></p>' + '</div>' + '<div id="userButton" class="fr">' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
/*
function setGameTips4(lastopplayer, pname, price, acount, bcount, backcounts) {
    var content = '<h3 id="endedPrice">[ ' + pname + ' ]竞拍已结束，' + lastopplayer + '以<span class="price">¥' + price + '</span>获得了该商品！' + '</h3>' + '<div id="orderExpiryDate">' + '<p>本次竞拍为全额返'+BEATNAME+'，返点工作将在第三个工作日进行。您一共消耗'+BEATNAME+'：<strong>' + acount + '</strong>，'+POINTBNAME+'：<strong>' + bcount + '</strong>，返点数额：<strong>' + backcounts + '</strong>闪点</p>' + '<p>竞拍已结束，请参与其他竞拍，切勿触犯' + WEBNAME + '一人多号规则，再次提醒用户阅读' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《违规处理》</a>' + '、' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《使用条款》</a>' + '</p>' + '</div>' + '<div id="userButton" class="fr">' + '<span class="button button-hilite">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="goToURL()">前往操作</button>' + '</span>' + '</span>' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
function setGameTips5(lastopplayer, price, pname) {
    var content = '<h3 id="endedPrice">恭喜，' + lastopplayer + '刚以' + '<span class="price">¥' + price + '</span>获得了商品[ ' + pname + ' ]</h3>' + '<div id="orderExpiryDate">' + '<p>本次竞拍为免费竞拍，无需消耗任何点数即可出价，更多活动请关注公告。</p>' + '<p>竞拍已结束，请参与其他竞拍，切勿触犯' + WEBNAME + '一人多号规则，再次提醒用户阅读' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《违规处理》</a>' + '、' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《使用条款》</a>' + '</p>' + '</div>' + '<div id="userButton" class="fr">' + '<span class="button button-hilite">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="goToURL()">前往操作</button>' + '</span>' + '</span>' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
*/


/**
 * 隐藏消息提示
 */
function HideTips() {
    $("#proTop").hide()
}

/**
 * 跳转会员管理
 */
function goToURL() {
    location.href = APP + '/Member/'
}







/**
 * 商品竞标历史出价
 */
function up_history() {
    var tid = window.game_tid;
    var bidNo = window.inibidjs;
    if (window.history_status == 1 && bidNo != '') {
        QueueFactory.request({
            type: "POST",
            dataType: "json",
            //timeout: _ajaxtimeout,
            url: ROOT + "/bidhistory.php?id=" + tid,
            success: function(data) {
                update_all_bidhistorylist(data.all, 1)
            }
        })
    }
}



/**
 * 填充竞标历史出价情况
 * @param d
 * @param n
 */
function update_all_bidhistorylist(d, n) {
    var tid = window.game_tid;
    var data_all = d;
    var htmlvar;
    var html_header = '<table class="chart"><thead><th width="20%">ID</th><th width="30%">IP</th><th width="20%">类型</th><th width="30%">出价</th></thead>';
    var html_footer = '</table><div class="pages cb" style="font-size:12px;"> <a jtcontent="由于网络原因，竞拍记录有可能不同步，请点击【马上整理出价记录!】" jtwidth="150" jttitle="提示" id="bidalllisttips" href="javascript:void(0);" onclick="ctrlauction(0);">[马上整理出价记录!]</a></div>';
    var html_body = '';
    var item_num = 0;
    var item_type = '';
    
    $.each(data_all, function(i, item) {
        if (i == 0) {
            window.r_id = item.id
        }
        item_num++;
        
        /*if (item.bidtype == 0) {
            item_type = '手动'
        } else {
            item_type = '分身'
        }*/
		
        //....现在默认是手动竞拍
        html_body += '<tr title="用户来自:' + item.locate + ',出价时间:' + item.bidtime + '"><td><a style="display:block; height:16px; overflow:hidden;" href="' + APP + '/User/center/id/' + item.mid + '" target="_blank" title="去看看' + item.nickname + '，昵称过长自动隐藏">' + item.nickname + '</a></td><td class="f10 notice">' + item.ip + '</td><td class="notice">' + '手动' + '</td><td class="f10 notice">¥' + item.price + '</td></tr>'
   
    });
    
    if (n == 1) {
        $('#bidHistoryList').html(html_header + html_body + html_footer);
        showTip("bidalllisttips")
    } else {
        if ($("#bidHistoryList table tr").size() > 9) {
            for (i = 0; i < item_num; i++) {
                $("#bidHistoryList table tr:last").remove()
            }
        }
        $("#bidHistoryList table").prepend(html_body)
    }
}









/**
 * 历史出价和我的出价
 * @param n
 */
function ctrlauction(n) {
    if (n == 0) {  
        window.chat_status = 0;
        window.self_status = 0;
        window.auto_status = 0;
        if (window.history_status == 0) {
            window.history_status = 1;
            
            up_history()   //历史出价
        }
    } else if (n == 1) {
        window.chat_status = 0;
        window.auto_status = 0;
        window.history_status = 0;
        if (window.self_status == 0) {
            window.self_status = 1;
            
            up_self()  //我的出价
        }
    } 
    
    
    /*  不知道何用
    else if (n == 2) {
        window.self_status = 0;
        window.auto_status = 0;
        window.history_status = 0;
        if (window.chat_status == 0) {
            window.chat_status = 1;
            up_chat()
        }
    } else if (n == 3) {
        window.chat_status = 0;
        window.self_status = 0;
        window.history_status = 0;
        up_auto()
    }
    */
    
}




/**
 * 我的出价
 */
function up_self() {
    var tid = window.game_tid;
    var islogin = getCookie('islogin');
    var js_saveprice = $('#js_saveprice').val();
    if (window.self_status == 1 && islogin) {
        $.getJSON(APP + "/Auction/ajaxmycount/id/" + tid, 
        function(data) {
            $('#self_point_a').html(data.self_point_a + "点");
            $('#self_point_b').html(data.self_point_b + "点");
            $('#self_price_point_a').html("¥" + data.self_price_point_a);
            $('#self_price_point_a2').html("¥" + data.self_price_point_a);
            $('#self_bidcount').html(data.self_bidcount + "次");
            if (data.self_price_point_a / js_saveprice > 0.8) {
                $('#bidNotes').html("<font color='red'>您很快就要达到保价了，请理性出价</font>")
            }
            if (js_saveprice - data.self_price_point_a > 0) {
                $('#self_price_pay').html("¥" + (js_saveprice - data.self_price_point_a))
            } else {
                $('#self_price_pay').html("¥0")
            }
        })
    } else {
        $('#self_point_a').html("0点");
        $('#self_point_b').html("0点");
        $('#self_clicks').html("0次");
        $('#self_bidcount').html("0次");
        $('#self_price_point_a').html("¥0");
        $('#self_price_point_a2').html("¥0");
        $('#self_next_spend').html("0点/每次点击");
        $('#self_price_point_a').html("¥0");
        $('#self_price_pay').html("¥" + js_saveprice)
    }
}







/***************************************  start  *********************************************/

/*

function up_chat() {
    var tid = window.game_tid;
    var islogin = getCookie('islogin');
    if (islogin != 1) {
        $("#msg").attr('disabled', 'disabled').attr('value', '请登录后刷新页面!');
        $("#sendmsg").attr('disabled', 'disabled')
    } else {
        $("#msg").removeAttr('disabled');
        $("#sendmsg").removeAttr('disabled')
    }
    if (window.chat_status == 1) {
        var uptime = window.timestamp;
        $.post(APP + "/Chat/get/", {
            time: uptime,
            tid: tid
        },
        function(xml) {
            $("#chatloading").remove();
            addMessages(xml)
        });
        window.setTimeout("up_chat()", 4000)
    }
}

var pClass = 'message_a';
function addMessages(xml) {
    var cClass;
    if ($("status", xml).text() == "2") return;
    window.timestamp = $("time", xml).text();
    $("message", xml).each(function(n, i) {
        var username = $("username", this).text();
        var mid = $("mid", this).text();
        var time = $("time", this).text();
        var ip = $("ip", this).text();
        var ptime = $("ptime", this).text();
        var content = $("text", this).text();
        if (pClass == 'message_a') {
            cClass = "message_b";
            pClass = "message_b"
        } else {
            cClass = "message_a";
            pClass = "message_a"
        }
        if (mid == "MTg2YTg=") {
            cClass = "paibanAdmin"
        }
        var htmlcode = '<tr><td class="' + cClass + '">' + '<p><span class="userName">' + username + '</span>' + '<span class="f10">' + ptime + '</span></p>' + '<p class="userMessage">' + toBreakWord(content, 30) + '</p>' + '</td></tr>';
        $("#chatList").append(htmlcode);
        $("#chatwindow").get(0).scrollTop = $("#chatList").get(0).scrollHeight
    });
    pClass = cClass
}





function up_auto() {
    if (window.auto_status == 1) {
        SetAutobid();
        window.setTimeout("up_auto()", 3000)
    }
}


*/




/**
 * 查询历史竞拍商品
 */
function gohistorylist() {
    var passurls;
    var brands = $("#brands").attr("value");
    var price = $("#price").attr("value");
    passurls = APP + "/Auction/historylist";
    if (brands != '0') {
        passurls = passurls + "/brands/" + brands
    }
    if (price != '0') {
        passurls = passurls + "/price/" + price
    }
    window.location.href = passurls
}

/**
 * 查询即将竞拍的商品
 */
function gofuturelist() {
    var passurls;
    var brands = $("#brands").attr("value");
    var savingprice = $("#savingprice").attr("value");
    passurls = APP + "/Auction/futurelist";
    if (brands != '0') {
        passurls = passurls + "/brands/" + brands
    }
    if (savingprice != '0') {
        passurls = passurls + "/savingprice/" + savingprice
    }
    window.location.href = passurls
}



/**
 * 查询正在竞拍的商品
 */
function godoinglist() {
    var passurls;
    var brands = $("#brands").attr("value");
    var savingprice = $("#savingprice").attr("value");
    passurls = APP + "/Auction/auctionnow";
    if (brands != '0') {
        passurls = passurls + "/brands/" + brands
    }
    if (savingprice != '0') {
        passurls = passurls + "/savingprice/" + savingprice
    }
    
    window.location.href = passurls
}























//.................分身的js操作

/* 初始化分身的变量 */
function iniautobid(){
	window.auto_status= 1;

	//分身设置按钮
	$("#mr_startbid").click(function(){
		var islogin=getCookie('islogin');
		if(!islogin){
			loadloginbox();
		}else{
			setdaemon();
		}
	});
	InitPageAutobid();
}

//第一次载入页面分身操作
function InitPageAutobid(){
	var tid=window.game_tid;
	var islogin=getCookie('islogin');
	if(islogin){
		$.post(ROOT+"/daemon.php", {"id":tid},function(dt){
			if(dt=='0'){
				window.auto_status = 0;
				autosetform(1);//0为开始设计disable,1为设计完enable
				//更新我的出价
				up_self();
			}else if(dt=='1'){
				window.auto_status = 1;
				autosetform(0);//0为开始设计disable,1为设计完enable
				up_auto();
			}
		},'json');
	}
}

//分身初始化操作
function SetAutobid(){
	var tid=window.game_tid;
	var islogin=getCookie('islogin');
	if(islogin){
		$.post( ROOT+"/daemon.php", {"id":tid},function(dt){
			if(dt=='0'){
				window.auto_status = 0;
				autosetform(1);//0为开始设计disable,1为设计完enable
				//更新我的出价
				up_self();
			}
		},'json');
	}
}

//设置分身
function setdaemon(){
	var tid=window.game_tid;
	$.post( ROOT+"/setdaemon.php",
			{"id":tid},
			function(msg){
				if(msg==1){
					window.auto_status= 1;
					//autosetform(0);//0为开始设计disable,1为设计完enable
					up_auto();
					showBidTip('autobid_tip','守秒已开启！');
				}else if(msg==0){
					showBidTip('autobid_tip','设置失败！');
				}else if(msg==2){
					showBidTip('autobid_tip','请先登录！');
				}else if(msg==3){
					showBidTip('autobid_tip','您的余额不足，请充值!<a href="javascript:paycountnow();" title="充值，获取闪点">【马上充值】</a>！');
				}else if(msg==4){
					showBidTip('autobid_tip','您已获得过商品，此为新人竞拍商品！');
				}else if(msg==5){
					showBidTip('autobid_tip','设置失败,竞拍不存在！');
				}else if(msg==6){
					showBidTip('autobid_tip','此为新人竞拍商品，请先进行账户安全认证！');
				}else if(msg==7){
					showBidTip('autobid_tip','本期是"N次拍"游戏,您的出价已经达到"N次拍"玩法的次数的上限！');
				}else if(msg==8){
					showBidTip('autobid_tip','设置失败,竞拍未开始！');
				}else if(msg==9){
					showBidTip('autobid_tip','设置失败,竞拍已结束！');
				}else if(msg==10){
					showBidTip('autobid_tip','设置失败,异常错误！');
				}else if(msg==11){
					showBidTip('autobid_tip','守秒已设置,不能重复设置！');	
				}else if(msg==12){
					showBidTip('autobid_tip','倒计时最后3秒内不允许设置守秒！');					
				}else{
					//showBidTip(id,'出价信息到达服务器时竞拍已经结束，下次请提早出价！');
				}

			});
}

function autosetform(n)
{   //0为开始设计disable,1为设计完enable
	if(n==0){
		$("#mr_startbid").removeClass("bidImgButton_zeroToBid");
		$("#mr_startbid").addClass("bidImgButton_zeroToBidDisabled");
		$("#mr_startbid").unbind();
	}else if(n==1){
		$("#mr_startbid").removeClass("bidImgButton_zeroToBidDisabled");
		$("#mr_startbid").addClass("bidImgButton_zeroToBid");
		iniautobid();
	}
}


function reSetAutobid() {
    var tid = window.game_tid;
    var islogin = getCookie('islogin');
    if (!islogin) {
        $("#mr_startbid").show();
        $("#mr_stopbid").hide();
        autosetform(0);
        return
    } else {
        $.post(APP + "/Bid/daemon", {
            "tid": tid,
            "flag": 1
        },
        function(dt) {
            $("#mr_startprice").val(dt.startprice);
            $("#mr_settingcount").val(dt.settingcount);
            $("#mr_bidcount").text(dt.bidcount)
        },
        'json')
    }
}


function unsetdaemon() {
    var tid = window.game_tid;
    var id = window.auto_id;
    $.post(APP + "/Bid/disposedaemon", {
        "id": id
    },
    function(msg) {
        if (msg == 0) {
            showBidTip('mr_stopbid', '请登陆后再试!')
        } else if (msg == 1) {
            showBidTip('mr_stopbid', '检查出错!')
        } else if (msg == 2) {
            showBidTip('mr_stopbid', '更新出错!')
        } else if (msg == 3) {
            showBidTip('mr_stopbid', '未到取消时间!')
        } else if (msg == 9) {
            dostyle_mr_stopbid()
        } else {}
    })
}

function dostyle_mr_startbid() {
    $("#mr_startbid").hide();
    $("#mr_stopbid").show();
    window.startautobid = 1;
    autosetform(0)
}

function dostyle_mr_stopbid() {
    $("#mr_stopbid").hide();
    $("#mr_startbid").show();
    window.startautobid = 0;
    autosetform(1)
}

function UpdateTime(num, se, toid) {
    $("#" + toid).attr("value", "[" + (se - num) + "秒]")
}

function UpdateTimeOn(toid, v) {
    $("#" + toid).attr("value", v);
    $("#" + toid).removeAttr("disabled")
}



/*
function exchange(id){
	var url=APP+"/Mall/buy/id/"+id;
	$.ajax({
		url: APP+"/Mall/buy/id/"+id,
		cache: false,
		success: function(msg){
			if(msg==1){
				showBidTip(id, '请登陆后再试!');
			} else if (msg == 2) {
				showBidTip(id, '操作错误!');
            }else{
                window.location.href = url;
			}
		}
	});
}

function buyurl(){
	var url=APP+"/Mall/index/";
	window.location.href = url;
}

function buycheck(){
	var queryString = $('#buyMallForm').formSerialize();
	var id=$("#id").val(); 
	
	$.post(APP+"/Mall/check", queryString,function(msg){
		if(msg=='0'){ 
			showBidTip(id,'兑换成功!');
			setTimeout("buyurl()",3000);			
		}else if(msg=='1'){ 
			showBidTip(id,'请登录!');
		}else if(msg=='2'){ 
			showBidTip(id,'操作错误!');
		}else if(msg=='3'){ 
			showBidTip(id,'数量不能为空!');
		}else if(msg=='4'){ 
			showBidTip(id,'收件人不能为空!');
		}else if(msg=='5'){ 
			showBidTip(id,'邮编不能为空!');
		}else if(msg=='6'){ 
			showBidTip(id,'收货地址不能为空!');
		}else if(msg=='7'){ 
			showBidTip(id,'收件人手机号不能为空!');
		}else if(msg=='8'){
			showBidTip(id, '积分不足!');
		}else if(msg=='9'){ 
			showBidTip(id,'库存不足!');
		}else{
			showBidTip(id, '兑换失败!');
		}
	});
}



function netSlow(){
	var btime = 'timeout';
	var intDelay = 30;
	var content = setGameDelay(intDelay, btime);
	$("#alertOrderContent").html(content);
	$("#proTop").show();
	var ids = window.inibidjs.split(",");
	for (var i = 0; i < ids.length; i++) {
		dotime(ids[i], 1800);
	}
	
	window.setTimeout("HideDelay('" + btime + "')", 10000);
}



function sendchat() {
    var islogin = getCookie('islogin');
    if (islogin == 1) {
        if ($("#msg").val() != '') {
            $.post(APP + "/Chat/add", {
                tid: game_tid,
                msg: $("#msg").val(),
                mid: $("#usermid").val(),
                username: $("#usernickname").val(),
                ip: $("#ip").val(),
                time: window.timestamp
            },
            function(xml) {
                $("#msg").val("");
                addMessages(xml)
            })
        }
    }
    return false
}

*/



 /***************************************  end  *********************************************/










